<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>发布活动</title>
<meta name="description" content="拉勾数据">
<meta name="keywords" content="二手房 房产经济 房企 开发商 拉勾数据 IFS">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="icon" type="image/png" href="assets/i/favicon.png">
<link rel="apple-touch-icon-precomposed"
	href="assets/i/app-icon72x72@2x.png">
<meta name="apple-mobile-web-app-title" content="eosms for IFS" />
<link rel="stylesheet" href="assets/css/amazeui.min.css" />
<link rel="stylesheet" href="assets/css/admin.css">
<script src="assets/ckeditor/ckeditor.js"></script>
</head>
<body>
	<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->

	<jsp:include page="/manage_header.do" flush="true" />

	<div class="am-cf admin-main">
		<!-- sidebar start -->
		<jsp:include page="/manage_tree.do" flush="true"></jsp:include>
		<!-- sidebar end -->

		<!-- content start -->
		<div class="admin-content">

			<div class="am-cf am-padding">
				<div class="am-fl am-cf">
					<strong class="am-text-primary am-text-lg">发布活动</strong> / <small>publish activity</small>
				</div>
			</div>
			<form id="searchactivity_form" class="am-form" action="show_add_publishactivity.do"
				method="post">
				<input
					type="hidden" name="page_num" id="page_num" value="0">
					<div class="am-tab-panel am-fade am-in am-active" id="tab1">
							<div class="am-g am-margin-top">
							<div class="am-u-sm-2 am-u-md-2 am-text-right">活动关标题</div>
									<div class="am-u-sm-2 am-u-md-2 am-text-right">
							<input type="text" name="searchtitle" id="searchtitle" value="${title}">

					</div>
				<div class="am-u-sm-2 am-u-md-2 am-text-right">活动关键字</div>
									<div class="am-u-sm-2 am-u-md-2 am-text-right">
							<input type="text" name="searchcontext" id="searchcontext" value="${context}">

					</div>
					<div class="am-u-sm-2 am-u-md-2 am-text-right">从当前时间起前几天的信息</div>
									<div class="am-u-sm-2 am-u-md-2 am-text-right">
							<input type="text" name="day" id="day" value="${day}">

					</div>
					  
								</div>
								</div>
								<div class="am-margin am-text-right">
								<button type="button" id="clear_button1"
								class="am-btn am-btn-primary am-btn-xs">清空</button>
								<button type="button" id="search_button"
								class="am-btn am-btn-primary am-btn-xs">查询</button>
								
									
								</div>
				
				</form>
				
			<div class="am-active am-text-left" ><button id="publish_button">编辑要发布的信息</button></div>
			<form id="publishactivity_form" class="am-form" action=""
				method="post">
				<input type="hidden" name="id" id="id" value="0"> 
				<div class="am-tabs am-margin" data-am-tabs>
				<ul class="am-tabs-nav am-nav am-nav-tabs">
						<li class="am-active"><a href="#tab1">编辑活动</a></li>
					</ul>
				<div class="am-tabs-bd" id="publish">
				<div class="am-tab-panel am-fade am-in am-active" id="tab1">
			
					<div class="am-g am-margin-top">	
					<div class="am-u-sm-3 am-u-md-3 am-text-right">活动标题</div>
					<div class="am-u-sm-3 am-u-md-3 am-text-right"><input type="text" name="title" id="title"></div>
						<div id="div_status">
									<div class="am-u-sm-3 am-u-md-3 am-text-right">活动的状态:</div>
									<div class="am-u-sm-3 am-u-md-3 am-text-right">
										<select class="selector1" id="status" name="status">
											<option value="">请选择状态</option>
											<option value="1">可用</option>
											<option value="0">禁用</option>
										</select>

									</div>
								</div>
								</div>
							
								
							<div class="am-g am-margin-top">
								<textarea id="editor1"></textarea>
							</div>
						</div>
						<div class="am-margin am-text-right">
						    
							<button type="button" id="clear_button"
								class="am-btn am-btn-primary am-btn-xs">清空</button>
									
							<button type="button" id="update_button"
								class="am-btn am-btn-primary am-btn-xs">修改</button>
								<button type="button" id="add_button"
								class="am-btn am-btn-primary am-btn-xs">发布</button>
		                   <button type="button" id="delete_button"
								class="am-btn am-btn-primary am-btn-xs">删除</button>
						</div>
					</div>
				</div>
			</form>
				<div class="am-g">
				<div class="am-u-sm-12">
					<form class="am-form">
						<table id="data_table"
							class="am-table am-table-striped am-table-hover table-main">
							<thead>
								<tr>
								<th class="table-title" width="20%">活动标题</th>
									<th class="table-title" width="50%">活动内容</th>
									<th class="table-title" width="20%">发布时间</th>
									<th class="table-title" width="10%">状态</th>
								
								</tr>
							</thead>
							<tbody id="data_tbody">
								<c:forEach var="activity" items="${activitys}" varStatus="s">
									<tr class="tr_click" activity_id="${activity.id}">
									<td>${activity.title}</td>
										<td>${activity.context}</td>
										<td>${activity.create_time}</td>
										<td><c:choose>
												<c:when test="${activity.status==1}">  
         											  可用     
   												</c:when>
												<c:otherwise> 
													   禁用 
  											    </c:otherwise>
											</c:choose></td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
						<div class="am-cf">
							共 <b id="pageCount">${page.allRow}</b> 条记录
							<div class="am-fr">
								<ul class="am-pagination">
									<c:choose>
										<c:when test="${page.currentPage==1}">
											<li class="am-disabled"><a href="#">«</a></li>
										</c:when>
										<c:when test="${page.currentPage!=1}">
											<li><a href="javascript:void(0)"
												onclick="choose_page(${page.currentPage-1})">«</a></li>
										</c:when>
									</c:choose>
									<c:forEach var="i" begin="1" end="${page.totalPage}" step="1">
										<c:choose>
											<c:when test="${page.currentPage==i}">
												<li class="am-active"><a href="javascript:void(0)"><c:out
															value="${i}" /></a></li>
											</c:when>
											<c:when test="${page.currentPage!=i}">
												<li><a href="javascript:void(0)"
													onclick="choose_page(${i})"><c:out value="${i}" /></a></li>
											</c:when>
										</c:choose>
									</c:forEach>
									<c:choose>
										<c:when test="${page.currentPage==page.totalPage}">
											<li class="am-disabled"><a href="#">»</a></li>
										</c:when>
										<c:when test="${page.currentPage!=page.totalPage}">
											<li><a href="javascript:void(0)"
												onclick="choose_page(${page.currentPage+1})">»</a></li>
										</c:when>
									</c:choose>
								</ul>
							</div>
						</div>
					</form>
				</div>
			</div>
			
		<!-- content end -->
   </div>
	</div>

	<a href="#" class="am-show-sm-only admin-menu"
		data-am-offcanvas="{target: '#admin-offcanvas'}"> <span
		class="am-icon-btn am-icon-th-list"></span>
	</a>

	<jsp:include page="/manage_foot.do" flush="true" />

	<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

	<!--[if (gte IE 9)|!(IE)]><!-->
	<script src="assets/js/jquery.min.js"></script>
	<!--<![endif]-->
	<script src="assets/js/amazeui.min.js"></script>
	<script src="assets/js/app.js"></script>
	 <script type="text/javascript">
$(function() {
	
	  CKEDITOR.replace('editor1');
	  $("#update_button").hide();
	  $("#delete_button").hide();
	  $("#div_status").hide();
	  $("#publishactivity_form").hide();
	//  var editor=CKEDITOR.replace('textarea');
	//页面初始化时默认新增机构，所以隐藏新增按钮
	$("#publish_button").click(function(){
		$("#publishactivity_form").show();
		
	});
	
	$("#update_button").click(function() {
		  var context = CKEDITOR.instances.editor1.getData();
          if(context!="")
         	 {
        	  var saveData={"id":$("#id").val()};
      		$.ajax({
      			contentType:"application/json",
      		    type : "POST",
      		    url : "<%=request.getContextPath()%>/add_activity.do?context="+context+"&status="+$("#status>option:selected").val()+"&title="+$("#title").val()+"",
      		    data : JSON.stringify(saveData),
      		    dataType: "json",
      		    success : function(data) {
      		        if(data.flag=="1"){
      		        	
      		        	 $('#searchactivity_form')[0].reset();
			    		 $("#searchactivity_form").submit();
      		        	$("#id").val(data.id);
      		        	//var t01 = $("#clients_table tr").length;
      		        	//$("#clients_table tr:gt(0):eq(t01-1)").remove();
      		        
      		        	CKEDITOR.instances.editor1.setData(data.context);
      		            alert("保存成功！");
      		         
      		        }
      		        else{
      		            alert("保存失败！");
      		        }
      		    },
      		    error :function(){
      		        alert("网络连接出错！");
      		    }
      		});
          }else{
        	  alert("内容不能为空！！！");
          }	
});
	$("#add_button").click(function(){
		
		$("#id").val(0);
		 $("#update_button").click();
		 $(".tr_click").removeClass("am-active");
	})
	
		 $("#delete_button").click(function(){
		
		 $.ajax({
				contentType:"application/json",
			    type : "GET",
			    url : "<%=request.getContextPath()%>/delete_activity.do?id="+$("#id").val()+"",
			    dataType: "json",
			    success : function(data) {
			        if(data.flag=="1"){
			        	 alert("删除成功！");
			        	 $("#id").val(0);
			    		 $('#searchactivity_form')[0].reset();
			    		 $("#searchactivity_form").submit();
			        }
			        else{
			            alert("保存失败！");
			        }
			    },
			    error :function(){
			        alert("网络连接出错！");
			    }
			});
		 $(".tr_click").removeClass("am-active");
		 $(this).addClass("am-active");
         $("#save_button").show();//显示
	 });
	
	
	 $(".tr_click").click(function(){
		 $.ajax({
				contentType:"application/json",
			    type : "GET",
			    url : "<%=request.getContextPath()%>/get_activity.do?id="+$(this).attr("activity_id"),
			    dataType: "json",
			    success : function(data) {
			    	$("#title").val(data.activity.title);
			    	$("#id").val(data.activity.id);
						        if(data.flag=="1"){
						        	CKEDITOR.instances.editor1.setData(data.activity.context);
						               if(data.activity.status==1)
						            	   {
						            	   $("#status option[value='1']").attr("selected","selected");
						            	   $("#status option[value='0']").removeAttr("selected");
						            	   }
						               if(data.activity.status==0)
						            	   {
						            	   $("#status option[value='0']").attr("selected","selected");
						            	   $("#status option[value='1']").removeAttr("selected");
						            	   }
								        	
								        
						        }else{
						        	alert("保存失败");
						        }
						       
						},
			    error :function(){
			        alert("网络连接出错！");
			    }
			});
		 $(".tr_click").removeClass("am-active");
		 $(this).addClass("am-active");
         $("#update_button").show();//显示
         $("#div_status").show();
         $("#delete_button").show();
         $("#publishactivity_form").show();
	 });
	
	$("#clear_button").click(function(){
		CKEDITOR.instances.editor1.setData("");
		$("#title").val("");
		$("#div_status").hide();
	})
	
	$("#search_button").click(function(){
		$("#searchactivity_form").submit();
	});
	
	$("#clear_button1").click(function(){
		$("#searchtitle").val('');
		$("#searchcontext").val('');
		$("#day").val('');
	
	})
	
	$("#search_button").click(function(){
		$("#searchactivity_form").submit();
	});
	
});
function choose_page(i){
	 $("#clear_button").click();
	$("#page_num").val(i);

	$("#searchactivity_form").submit();
}
</script>
</body>
</html>
